Skip to content

fix(core): ignore unsafe project provider endpoints - #16

Closed
BunsDev wants to merge 1 commit into
mainfrom
codex/fix-provider-api-key-leakage-vulnerability
Closed

fix(core): ignore unsafe project provider endpoints#16
BunsDev wants to merge 1 commit into
mainfrom
codex/fix-provider-api-key-leakage-vulnerability

Conversation

@BunsDev

@BunsDev BunsDev commented Jun 1, 2026

Copy link
Copy Markdown
Member

Motivation

  • Prevent untrusted project settings from causing provider credential or prompt exfiltration by disallowing project-supplied API keys and remote API bases for non-local providers.
  • Preserve developer intent to allow local-only provider endpoints (Ollama, LM Studio, llama.cpp) that are safe to configure per-project.
  • Ensure merging project settings into the effective Config does not clobber global/trusted credentials or bases.

Description

  • Sanitize project-loaded Settings via Settings::sanitize_project_settings: strip top-level config.api_key and remove per-provider api_key values, and clear api_base for any provider not explicitly allowed as local (ollama, lmstudio/lm-studio, llamacpp/llama-cpp/llama-server). (changes in src-rust/crates/core/src/lib.rs)
  • Add is_project_api_base_allowed and is_default_provider_config helpers to centralize allowed-local-provider logic and to drop no-op provider entries from project settings. (in core/src/lib.rs)
  • Change settings merge behavior to merge provider metadata without overwriting global credentials or trusted API bases by using merge_provider_configs for provider_configs/providers during Settings::merge. (in core/src/lib.rs)
  • Make the project-settings discovery/merge helpers accessible to tests (find_project_settings and merge are pub(crate)) and add unit tests exercising sanitization and merge semantics to prevent regressions. (tests added in core/src/lib.rs)

Testing

  • Ran cargo test --package claurst-core test_project_settings_strip_remote_provider_credentials_and_api_base and the test passed.
  • Ran cargo test --package claurst-core test_project_provider_sanitization_preserves_global_api_base and cargo check --package claurst-core, both succeeded.
  • Attempted workspace-wide checks (cargo check --workspace, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace) but these are blocked in the current environment due to a missing system dependency (alsa.pc) required by alsa-sys and therefore could not complete here.

Codex Task

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens hierarchical settings loading to prevent untrusted project-level settings (.coven-code/settings.json{c}) from injecting provider credentials or unsafe endpoints into the effective configuration, while still permitting per-project configuration for known local-only providers.

Changes:

  • Sanitize project-loaded Settings to strip top-level config.api_key, remove per-provider api_key, and clear api_base for non-allowed providers.
  • Adjust Settings::merge to merge provider configs field-by-field so project settings don’t clobber trusted/global credentials or API bases.
  • Add unit tests covering provider sanitization and merge behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1678 to +1682
fn sanitize_project_provider_config(provider_id: &str, provider: &mut ProviderConfig) {
provider.api_key = None;
if !is_project_api_base_allowed(provider_id) {
provider.api_base = None;
}
Comment on lines 1685 to 1687
/// Merge two settings with `override_settings` taking priority.
/// Simple strategy: override wins for all scalar fields; Vecs are
/// concatenated (deduped); HashMaps are merged (override wins on collision).
@BunsDev

BunsDev commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

Closing this as superseded by #15, merged in 0a96406.

#15 strips project-controlled provider routing, provider endpoint maps, provider configs, and config API keys before merge, while preserving safe project preferences and trusted global provider settings. That covers the remaining concern here: local-provider IDs alone are not enough if the project can still point api_base at a non-local endpoint.

Thanks @BunsDev

@BunsDev BunsDev closed this Jun 3, 2026
@BunsDev
BunsDev deleted the codex/fix-provider-api-key-leakage-vulnerability branch June 15, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants